#!/bin/sh

# Copyright (C) 2008 Arthur Henrique Penteado Furlan <arthur.furlan@gmail.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# On Debian systems, you can find the full text of the license in
# /usr/share/common-licenses/GPL-2

# ooops... check the usage! :)
if [[ $# < 1 ]]; then
    echo "Usage: $0 <FILE>"
    exit 1
fi

# find all matches of a student's GRR (internal code of UFPR) and append the
# student's name after its
cat $1 | while read LINE; do
    GRR=$(echo $LINE | sed 's/^.*\(GRR\s*[0-9]\{8\}\).*$/\1/') # ugly! =/
    if [[ $GRR != $LINE ]]; then
        NAME=$(finger $GRR | grep 'Name:' | tr -s ' ' | cut -d ' ' -f 4-)
        LINE=$(echo $LINE | sed "s/${GRR}/${GRR} ${NAME}/g")
    fi
    echo $LINE
done
